# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtkglext
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=3
pkgdesc="opengl extensions for gtk2 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://gtkglext.sourceforge.io/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gtk2" "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/sourceforge/gtkglext/gtkglext-${pkgver}.tar.bz2"
        "gtk2.20.patch"
        "gtkglext-1.0.6-pangox.patch")
sha256sums=('16bd736074f6b14180f206b7e91263fc721b49912ea3258ab5f094cfa5497f51'
            '864c6963c4a2f4f69f1f028ecee6c821a4f4d5aba142f2e07898aede825ce9ea'
            '064f61783e86c622f6f725b0586d5d75b5b8b67d20cc606fb4234a6df8da97ad')

prepare() {
  cd "${srcdir}/gtkglext-${pkgver}"
  patch -Np1 -i "${srcdir}/gtk2.20.patch"
  patch -p1 -R -i "${srcdir}/gtkglext-1.0.6-pangox.patch"
  autoconf --force
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -r "${srcdir}/gtkglext-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  CFLAGS+=" -fcommon"  # work around gcc 10 being stricter here

  # an argument passed to glib-mkenums starts with a c++ comment
  export MSYS2_ARG_CONV_EXCL="/*"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-gdktarget=win32 \
    --without-x \
    --disable-glibtest \
    --disable-gtktest \
    --disable-debug

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
